﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SilverTile.Xaml;
using SilverTile;
using System.Linq;

namespace SilverTileApp
{
    //public class GameSprite : AnimatedSprite
    //{

    //    protected Direction _direction = Direction.None;

    //    public int TargetX { get; set; }
    //    public int TargetY { get; set; }

    //    public GameSprite(int width, int height) : base(width, height)
    //    {
    //        Fps = 10;
    //    }

    //    protected void AddAnimation(ResourceDictionary resources, string name, params string[] resourceNames)
    //    {
    //        IFrame[] frames = resourceNames.Select(r => ((SpriteFrame)resources[r]).Frame).ToArray();
    //        AddAnimations(name, frames);
    //    }

    //    public override void Update(TimeSpan timeSinceLastFrame)
    //    {

    //        int dx = Math.Sign(TargetX - X);
    //        int dy = Math.Sign(TargetY - Y);

    //        Collision willCollide = WillCollideIfMoving(dx, dy);

    //        bool moved = false;

    //        if ((dx == 1 && willCollide.IsNotSet(Collision.Right)) || (dx == -1 && willCollide.IsNotSet(Collision.Left)))
    //        {
    //            // Can move horizontally
    //            if (dx == 1 && _direction != Direction.Right)
    //            {
    //                _direction = Direction.Right;
    //                SetActiveAnimation("Right");
    //            }

    //            if (dx == -1 && _direction != Direction.Left)
    //            {
    //                _direction = Direction.Left;
    //                SetActiveAnimation("Left");
    //            }

    //            X += dx;
    //            moved = true;
    //        }

    //        if (!moved)
    //        {
    //            if ((dy == 1 && willCollide.IsNotSet(Collision.Bottom)) || (dy == -1 && willCollide.IsNotSet(Collision.Top)))
    //            {
    //                // Can move vertically
    //                if (dy == 1 && _direction != Direction.Down)
    //                {
    //                    _direction = Direction.Down;
    //                    SetActiveAnimation("Down");
    //                }

    //                if (dy == -1 && _direction != Direction.Up)
    //                {
    //                    _direction = Direction.Up;
    //                    SetActiveAnimation("Up");
    //                }

    //                Y += dy;
    //                moved = true;
    //            }
    //        }

    //        if (moved)
    //        {
    //            base.Update(timeSinceLastFrame);
    //        }
    //    }

    //    protected Collision WillCollideIfMoving(int dx, int dy)
    //    {
    //        return Viewport.SpriteWillCollideWithBackground(this, X + dx, Y + dy, 0);
    //    }

    //}
}
